"""
迭代器

两个方法
__next__
__iter__返回自身

"""


class SumClass:
    def __init__(self, max_num):
        self.result = 0
        self.max_num = max_num

    def __iter__(self):
        return self

    def __next__(self):
        self.result += 5
        if self.result >= self.max_num:
            # raise Exception("超过最大值了")  # 报错
            raise StopIteration  # 停止迭代
        return self.result



class MyIterClass:
    def __init__(self, max_num):
        self.max_num = max_num
        self.num = 0

    def __iter__(self):
        return self

    def __next__(self):
        self.num += 10
        if self.num < self.max_num:
            return self.num
        else:
            raise StopIteration("越界了")


sc = SumClass(300)
for s in sc:
    print(s)

print("=" * 30)

aa = MyIterClass(100)
for a in aa:
    print(a)